<%--
  Created by IntelliJ IDEA.
  User: WuLianFa
  Date: 2018/6/1 0001
  Time: 14:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%
    request.setCharacterEncoding("UTF-8");
    String path = request.getContextPath();
%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>物品出库-修改界面</title>
    <script type="text/javascript" src="<%=path%>/My97DatePicker/WdatePicker.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=path%>/CSS/backLayout.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/CSS/bombBox.css">
    <script type="text/javascript" src="<%=path%>/JQuery/jquery-1.8.2.js"></script>
    <%@ include file="/WEB-INF/JSP/ajax.jsp" %>
    <script type="text/javascript" src="<%=path%>/HoganJS/handlebars-v4.0.11.js"></script>
</head>
<style>
    select {
        width: 234px;
        height: 31px
    }

    .gn_name {
        padding-top: 5px
    }

    .div_zilei {
        width: 100%;
        height: 30px
    }

    .tr {
        height: 40px;
        background: #a9bbe0
    }

    .tr td {
        font-size: 14px;
        color: #ffffff
    }

    .tr_td {
        height: 40px;
    }

    .tr_td td {
        border-bottom: 1px solid #ededed;
        text-align: center;
    }

    tr td:nth-child(1) {
        font-size: 14px;
        color: #cccccc
    }

    .date {
        border: 0;
        background: #ffffff;
        text-align: center;
    }

    .tr_td td:nth-child(1) {
        border-left: 1px solid #cccccc;
    }

    .tr_td td:nth-child(3) {
        border-right: 1px solid #cccccc;
    }

    .addTable.deleteTable:HOVER {
        cursor: pointer;
    }

    input[type='checkbox'] {
        width: 15px
    }

    .fseq2 {
        border: none;
        color: #cccccc;
        text-align: center;
    }

</style>
<body style="background: #f5f5f5">
<div class="main">
    <div class="weizhi">
        库存管理>>物品出库>>修改
    </div>
    <div class="modal-data1">
        <div style="height: 60px">
            <ul>
                <li style="text-align: left; margin-left: 60px; height: 40px; line-height: 40px">
                    <span>物品名称：</span><span><input style="width: 100px" class="goodsName" type="text"></span>
                    <span>物品类型：</span><span><input style="width: 100px" class="goodsType" type="text"></span>
                    <span>物品规格：</span><span><input style="width: 100px" class="goodsGgid" type="text"></span>
                    <span><button class="findBtn1" onclick="outwarehouseGoodsMassage()">查询</button></span>
                </li>
            </ul>
        </div>
        <div style="width:1100px; height:350px; overflow:scroll;">
            <form action="">
                <table id="goodsTableAppendTo" class="head1"
                       style="width: auto; white-space: nowrap; border-spacing: 0px">
                    <tr style="background: #f2f2f2; height: 30px; line-height: 20px;"
                        class="sel">
                        <td align="left"><input type="checkbox" class="goodsTableCheckbox"/></td>
                        <td align="left">物品名称</td>
                        <td align="left">物品类型</td>
                        <td align="left">物品规格</td>
                        <td align="left">物品单价</td>
                        <td align="left">创建人</td>
                        <td align="left">创建时间</td>
                        <td align="left">修改人</td>
                        <td align="left">修改时间</td>
                    </tr>
                    <%--ajax拼接--%>
                </table>
            </form>
        </div>
        <button class="subtn1" style="width: 200px; position: absolute; bottom: 25px; font-size: 16px; left: 170px">确定
        </button>
        <button class="btn" style="width: 200px; position: absolute; bottom: 25px; font-size: 16px; right: 170px">关闭
        </button>
    </div>
    <div class="div_body" style="box-shadow: 0 0 5px #cccccc;height: 950px">
        <div class="div_form">
            <form action="<%=path%>/DrivingSys/updateOutwarehouseMassage" class="form" onsubmit="return checkSubmit()">
                <div class="div_input_hang">
                    <div class="input_hang">
                        <span class="gn_name">驾校&nbsp;:&nbsp;</span>
                        <input type="text" name="ckSchoolid" value="${outwarehousetable.ckSchoolid}"
                               style="color: gray;"
                               readonly="readonly"/>
                        <input type="hidden" name="ckId" value="${outwarehousetable.ckId}"/>
                    </div>
                    <div class="input_hang">
                        <span class="gn_name">出库用途&nbsp;:&nbsp;</span>
                        <input type="text" name="ckOutwarehouseuse" value="${outwarehousetable.ckOutwarehouseuse}"
                               style="color: gray;"/>
                    </div>
                    <div class="input_hang">
                        <span class="gn_name">出库接收方&nbsp;:&nbsp;</span>
                        <input type="text" name="ckOutwarehouseaccepter"
                               value="${outwarehousetable.ckOutwarehouseaccepter}" style="color: gray;"/>
                    </div>
                </div>

                <div class="div_zilei">
                    <div style="width: 75%;text-align: right;">
                        <img src="<%=path%>/image/insert2323.jpg" class="addTable">
                        <span style="padding-right: 20px;color: #a9bbe0;font-size: 14px" class="addTable">添加</span>
                        <img src="<%=path%>/image/delete212.png" class="deleteTable">
                        <span style="color: #a9bbe0;font-size: 14px;" class="deleteTable">删除</span>
                    </div>
                </div>

                <div style="min-height: 500px;width: 75%;padding-left: 90px;">
                    <div style="overflow:scroll;height: 500px;width: 100%">
                        <table width="100%" align="center" id="table1" style="min-height:50px;border-spacing:0;"
                               class="outwarehouseAppendTo">
                            <tr class="tr">
                                <td align="left"><input type="checkbox" class="outwarehouseCheckbox"></td>
                                <td align="left">物品名称</td>
                                <td align="left">物品类型</td>
                                <td align="left">物品规格</td>
                                <td align="left">物品单价</td>
                                <td align="left">物品出库单价</td>
                                <td align="left">出库物品数量</td>
                                <td align="left">出库物品总价</td>
                            </tr>
                            <c:forEach items="${outwarehousechildren}" var="outwarehouse">
                                <tr>
                                    <td><input type='checkbox' name='outwarehouseCheckboxName'/></td>
                                    <td><input readonly='readonly' name='ckOutwarehousegoodsname' style='height: 27px'
                                               type='text' value='${outwarehouse.ckOutwarehousegoodsname}'></td>
                                    <td><input readonly='readonly' name='ckOutwarehousegoodstype' style='height: 27px'
                                               type='text' value='${outwarehouse.ckOutwarehousegoodstype}'></td>
                                    <td><input readonly='readonly' name='ckOutwarehouseggid' style='height: 27px'
                                               type='text' value='${outwarehouse.ckOutwarehouseggid}'></td>
                                    <td><input readonly='readonly' name='ckOutwarehousegoodsprice' style='height: 27px'
                                               type='text' value='${outwarehouse.ckOutwarehousegoodsprice}'></td>
                                    <td><input name='ckOutwarehouseprice' style='height: 27px' type='text'
                                               value='${outwarehouse.ckOutwarehouseprice}' placeholder='输入出库单价'></td>
                                    <td><input name='ckOutwarehousequantity' onblur='countOutwarehouseTotalPrices(this)'
                                               style='height: 27px' type='text'
                                               value='${outwarehouse.ckOutwarehousequantity}' placeholder='输入出库单价'></td>
                                    <td><input readonly='readonly' name='ckOutwarehousetotalprices' style='height: 27px'
                                               type='text' value='${outwarehouse.ckOutwarehousetotalprices}'></td>
                                </tr>
                            </c:forEach>
                            <%--ajax拼接--%>
                        </table>
                    </div>
                </div>


                <div class="div_input_hang" style="margin-top: 50px">
                    <div class="input_hang">
                        <span class="gn_name">审核人&nbsp;:&nbsp;</span>
                        <input name="ckAuditor" readonly="readonly" value="${outwarehousetable.ckAuditor}"
                               style="color: gray;" type="text"/>
                    </div>
                    <div class="input_hang">
                        <span class="gn_name">审核状态&nbsp;:&nbsp;</span>
                        <input name="ckAuditstatus" readonly="readonly" value="${outwarehousetable.ckAuditstatus}"
                               style="color: gray;" type="text"/>
                    </div>
                    <div class="input_hang">
                        <span class="gn_name">创建人&nbsp;:&nbsp;</span>
                        <input name="ckCreator" readonly readonly="readonly" value="${outwarehousetable.ckCreator}"
                               style="color: gray;"
                               type="text"/>
                    </div>
                    <div class="input_hang">
                        <span class="gn_name">创建时间&nbsp;:&nbsp;</span>
                        <input name="ckCreationtime" style="color: gray;" readonly="readonly"
                               value="${outwarehousetable.ckCreationtime}"
                               type="text"/>
                    </div>
                </div>

                <div class="div_tj" style="padding-top: 0px">
                    <div>
                        <input class="input_submit bc" value="" type="submit">
                    </div>
                    <div>
                        <input type="button" class="input_back fh" value="" onclick="back()"/>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">

    //弹出物品信息模式框
    $(".addTable").click(function () {
        $('.modal-data1').css('visibility', 'visible');
        readonly = 'readonly'
        outwarehouseGoodsMassage();
    })
    //关闭物品信息模式框
    $(".btn").click(function () {
        $('.modal-data1').css('visibility', 'hidden');
    })

    //根据名称，类型，规格查询
    function outwarehouseGoodsMassage() {
        var goodsName = $(".goodsName").val();//要搜索的物品名称
        var goodsType = $(".goodsType").val();//要搜索的物品名称
        var goodsGgid = $(".goodsGgid").val();//要搜索的物品名称
        $.ajax({
            url: '<%=path%>/DrivingSys/outwarehouseGetGoodsMassage',
            type: "post",
            data: {'goodsName': goodsName, 'goodsType': goodsType, 'goodsGgid': goodsGgid},
            dataType: "json",
            success: function (data) {
                if (data.goodstables == null || data.goodstables == '') {
                    $(".addGoodsTableAppendToRemove").remove();
                    var str = "<tr class='addGoodsTableAppendToRemove'>" +
                        "<th colspan='13'>" +
                        "<span>抱歉,没有任何相关的记录信息!</span>" +
                        "</th>" +
                        "</tr>";
                    $("#goodsTableAppendTo").append(str);
                } else {
                    $(".addGoodsTableAppendToRemove").remove();
                    for (var i = 0; i < data.goodstables.length; i++) {
                        var str = "<tr ondblclick='doubleClickChooseGoods(\"" + data.goodstables[i].wpId + "\")' class='addGoodsTableAppendToRemove'>" +
                            "<td><input type='checkbox' name='addGoodsTableCheckboxname' value='" + data.goodstables[i].wpId + "'/></td>" +
                            "<td>" + data.goodstables[i].wpName + "</td>" +
                            "<td>" + data.goodstables[i].wpType + "</td>" +
                            "<td>" + data.goodstables[i].wpGgid + "</td>" +
                            "<td>" + data.goodstables[i].wpPrice + "</td>" +
                            "<td>" + data.goodstables[i].wpCreator + "</td>" +
                            "<td>" + data.goodstables[i].wpCreationtime + "</td>" +
                            "<td>" + data.goodstables[i].wpLastmodifier + "</td>" +
                            "<td>" + data.goodstables[i].wpLastmodificationtime + "</td>" +
                            "</tr>";
                        $("#goodsTableAppendTo").append(str);
                    }
                }
            },
            error: function () {
                alert("出现了一个错误！");
            }
        })
    }

    //物品弹窗双击选择物品
    function doubleClickChooseGoods(wpId) {
        $.ajax({
            url: '<%=path%>/DrivingSys/outwarehouseGetGoodsMassageById',
            type: "post",
            data: {'wpId': wpId},
            dataType: "json",
            success: function (data) {
                for (var i = 0; i < data.goodstables.length; i++) {
                    var str = "<tr>" +
                        "<td><input type='checkbox' name='outwarehouseCheckboxName'/></td>" +
                        "<td><input readonly='readonly' name='ckOutwarehousegoodsname' style='height: 27px' type='text' value='" + data.goodstables[i].wpName + "'></td>" +
                        "<td><input readonly='readonly' name='ckOutwarehousegoodstype' style='height: 27px' type='text' value='" + data.goodstables[i].wpType + "'></td>" +
                        "<td><input readonly='readonly' name='ckOutwarehouseggid' style='height: 27px' type='text' value='" + data.goodstables[i].wpGgid + "'></td>" +
                        "<td><input readonly='readonly' name='ckOutwarehousegoodsprice' style='height: 27px' type='text' value='" + data.goodstables[i].wpPrice + "'></td>" +
                        "<td><input name='ckOutwarehouseprice' style='height: 27px' type='text' placeholder='输入出库单价'></td>" +
                        "<td><input name='ckOutwarehousequantity' onblur='countOutwarehouseTotalPrices(this)' style='height: 27px' type='text' placeholder='输入出库数量'></td>" +
                        "<td><input readonly='readonly' name='ckOutwarehousetotalprices' style='height: 27px' type='text'></td>" +
                        "</tr>";
                    $(".outwarehouseAppendTo").append(str);
                }
            },
            error: function () {
                alert("出现了一个错误！");
            }
        })
        $('.modal-data1').css('visibility', 'hidden');//关闭添加物品弹窗
    }

    //全选(添加物品弹窗)
    $('.goodsTableCheckbox').click(function () {
        if ($(this).attr("checked")) {
            $("input[name='addGoodsTableCheckboxname']").prop("checked", true)
        } else {
            $("input[name='addGoodsTableCheckboxname']").removeAttr('checked')
        }
    })

    //全选(增加出库记录页面)
    $('.outwarehouseCheckbox').click(function () {
        if ($(this).attr("checked")) {
            $("input[name='outwarehouseCheckboxName']").prop("checked", true)
        } else {
            $("input[name='outwarehouseCheckboxName']").removeAttr('checked')
        }
    })

    //确定把信息填入
    $(".subtn1").click(function () {
        var findid = document.getElementsByName("addGoodsTableCheckboxname");
        var wpIdArray = new Array();
        var j = 0;
        for (var i = 0; i < findid.length; i++) {
            if (findid[i].checked) {
                wpIdArray[j] = findid[i].value;
                j++;
            }
        }
        if (wpIdArray == null || wpIdArray == "") {
            alert("请至少选择一条数据！")
            return false;
        }
        $.ajax({
            url: '<%=path%>/DrivingSys/outwarehouseGetGoodsMassageById',
            type: "post",
            data: {'wpIdArray': JSON.stringify(wpIdArray)},
            dataType: "json",
            success: function (data) {
                for (var i = 0; i < data.goodstables.length; i++) {
                    var str = "<tr>" +
                        "<td><input type='checkbox' name='outwarehouseCheckboxName'/></td>" +
                        "<td><input readonly='readonly' name='ckOutwarehousegoodsname' style='height: 27px' type='text' value='" + data.goodstables[i].wpName + "'></td>" +
                        "<td><input readonly='readonly' name='ckOutwarehousegoodstype' style='height: 27px' type='text' value='" + data.goodstables[i].wpType + "'></td>" +
                        "<td><input readonly='readonly' name='ckOutwarehouseggid' style='height: 27px' type='text' value='" + data.goodstables[i].wpGgid + "'></td>" +
                        "<td><input readonly='readonly' name='ckOutwarehousegoodsprice' style='height: 27px' type='text' value='" + data.goodstables[i].wpPrice + "'></td>" +
                        "<td><input name='ckOutwarehouseprice' style='height: 27px' type='text' placeholder='输入出库单价'></td>" +
                        "<td><input name='ckOutwarehousequantity' style='height: 27px' onblur='countOutwarehouseTotalPrices(this)' type='text' placeholder='输入出库数量'></td>" +
                        "<td><input readonly='readonly' name='ckOutwarehousetotalprices' style='height: 27px' type='text'></td>" +
                        "</tr>";
                    $(".outwarehouseAppendTo").append(str);
                }
            },
            error: function () {
                alert("出现了一个错误！");
            }
        })
        $('.modal-data1').css('visibility', 'hidden');//关闭添加物品弹窗
    });

    //返回
    function back() {
        location = '<%=path%>/DrivingSys/outwarehouse/look.action';
    }

    //删除选中的行
    $(".deleteTable").click(function () {
        var names = document.getElementsByName("outwarehouseCheckboxName");
        var flag = false;//标记判断是否选中一个
        for (var i = 0; i < names.length; i++) {
            if (names[i].checked) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            alert("请最少选择一项删除！");
            return false;
        }
        $("input[name='outwarehouseCheckboxName']:checked").each(function () { // 遍历选中的checkbox
            n = $(this).parents("tr").index();  // 获取checkbox所在行的顺序
            $("table#table1").find("tr:eq(" + n + ")").remove();
        });
    })


    //数量失去焦点计算金额
    function countOutwarehouseTotalPrices(obj) {
        var intputOutwarehousequantity = $(obj).val();
        var inputOutwarehousePrice = $(obj).parent().prev().children("input[name='ckOutwarehouseprice']").val();
        if (inputOutwarehousePrice == null || inputOutwarehousePrice == '') {
            alert("请输入出库单价！");
            return false;
        }
        if (intputOutwarehousequantity == null || intputOutwarehousequantity == '') {
            alert("请输入出库数量！");
            return false;
        }
        var totalPrices = parseInt(inputOutwarehousePrice) * parseInt(intputOutwarehousequantity);
        $(obj).parent().next().children("input[name='ckOutwarehousetotalprices']").val(totalPrices);
    }

    //保存
    function checkSubmit() {
        debugger;
        var ckOutwarehouseprice = document.getElementsByName("ckOutwarehouseprice");
        var ckOutwarehousequantity = document.getElementsByName("ckOutwarehousequantity");
        var ckOutwarehousegoodsname = document.getElementsByName("ckOutwarehousegoodsname");
        for (var i = 0; i < ckOutwarehouseprice.length; i++) {
            if (ckOutwarehouseprice[i].value == null || ckOutwarehouseprice[i].value == "") {
                alert("你有未填项！");
                return false;
            }
        }
        for (var i = 0; i < ckOutwarehousequantity.length; i++) {
            if (ckOutwarehousequantity[i].value == null || ckOutwarehousequantity[i].value == "") {
                alert("你有未填项！");
                return false;
            }
        }
        if (ckOutwarehousegoodsname.length == 0) {
            alert("请至少添加一条数据！");
            return false;
        }
    }

</script>
</html>